### CCE

// 安全、ssh凭证
resource "huaweicloud_compute_keypair" "this" {
  name       = format("%s-terraform", local.welink)
  public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDEsG8+9oGzomG9sI2Mlv/rzZ8UCPtw7havcbKGPtHaX5PFeNTxAOCzJrhuuc6VjSeqVQVSQfFeeCidQaq+9avwm2yC2n80ScFoMyP7iy/oxmptJ5encT6cSTn+KrkVycIBswxyT7dl8vJo0IngXNPqF/ORppK4gjTxGxF/cS/wAE7/6zpqLMydTjUT2PSU+DV2FJ8WyzYxfEXfIyrdM+s67BeEktDAHv4aOFFWbVgB9TefmV0O/xGtOyRJ0FQsYQ+xntGPUdilulpfTioRegkEn/BR36tXNPr9lVY7IuXcJ867AqKxyNs4LMIW4GMUIKVwTjAPx8xiuTs2Z5CrUXCB ops@xiaoan.local"
}


resource "huaweicloud_vpc_eip" "this" {
  count = var.cce_create ? 1 : 0

  publicip {
    type = "5_bgp"
  }
  bandwidth {
    name        = var.cce_bandwidth_name
    size        = 8
    share_type  = "PER"
    charge_mode = "traffic"
  }
  #enterprise_project_id = var.enterprise_project_id
  depends_on = [huaweicloud_vpc_subnet.this]
}

resource "huaweicloud_cce_cluster" "this" {
  count = var.cce_create ? 1 : 0
  name                   = var.cce_cluster_name
  flavor_id              = var.cce_cluster_flavor
  cluster_version        = var.cce_cluster_version
  vpc_id                 = huaweicloud_vpc.this.id
  subnet_id              = huaweicloud_vpc_subnet.this.0.id
  container_network_type = "overlay_l2"
  eip                    = huaweicloud_vpc_eip.this[0].address
  #enterprise_project_id = var.enterprise_project_id
  depends_on = [huaweicloud_vpc_subnet.this, huaweicloud_vpc_eip.this]
}

resource "huaweicloud_cce_node_pool" "node_pool" {
  cluster_id               = huaweicloud_cce_cluster.this.0.id
  name                     = var.cce_nodepool_name
  os                       = var.cce_nodepool_os
  initial_node_count       = 1
  flavor_id                = var.cce_nodepool_flavor
  key_pair                 = huaweicloud_compute_keypair.this.id
  scall_enable             = true
  min_node_count           = 1
  max_node_count           = 10
  scale_down_cooldown_time = 100
  priority                 = 1
  type                     = "vm"

  root_volume {
    size       = 40
    volumetype = "SAS"
  }
  data_volumes {
    size       = 100
    volumetype = "SAS"
  }
}

/*
resource "huaweicloud_cce_addon" "addon_test" {
  cluster_id    = huaweicloud_cce_cluster.this.0.id
  template_name = "metrics-server"
  version       = "1.0.0"
}
*/
